//<!-- License -->
package eu.datafusion.log4soa.model.referencedata;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import eu.datafusion.log4soa.model.DataProtection;

import javax.persistence.Cacheable;
import javax.persistence.JoinColumn;

/**
 * Operation represents service operation reference data entity
 * @author Ivo.Mitov@datafusion.eu
 *
 */
@Entity
@Table(name = "OPERATIONS")
@Cacheable
public class Operation extends BaseReferenceData  implements Serializable {

	private static final long serialVersionUID = 8574830723561999537L;
	
	/**
	 * service immutable property
	 */
	@ManyToOne
	@JoinColumn(name = "SERVICE_ID", referencedColumnName = "ID", updatable = false, nullable = false)
	private Service service;

	/**
	 * @param service required immutable property
	 * @param name required immutable property <tt>name</tt> must be unique per Operation class instances
	 * @param dataProtection
	 * @param description optional property
	 */
	public Operation(Service service,String name,DataProtection dataProtection, String description) {
		super(name,dataProtection,description);
		this.setService(service);
	}
	
	/**
	 * @param service required immutable property
	 * @param name required immutable property <tt>name</tt> must be unique per Operation class instances
	 * @param dataProtection
	 */
	public Operation(Service service,String name,DataProtection dataProtection) {
		this(service,name,dataProtection,null);
	}
	
	/**
	 * @param service required immutable property
	 * @param name required immutable property <tt>name</tt> must be unique per Operation class instances
	 * @param description optional property
	 */
	public Operation(Service service,String name,String description) {
		this(service,name,DataProtection.UNPROTECTED,description);
	}
	
	/**
	 * @param service required immutable property
	 * @param name required immutable property <tt>name</tt> must be unique per Operation class instances
	 */
	public Operation(Service service,String name) {
		this(service,name,DataProtection.UNPROTECTED);
	}
	
	/**
	 * default constructor required by JPA
	 */
	protected Operation(){
		
	}
	
	/** 
	 * Getter of the immutable required property <tt>service</tt>
	 * @return  Returns the service.
	 */
	public Service getService() {
		return service;
	}

	/** 
	 * Setter of the immutable required property <tt>service</tt> used in constructor
	 * @param service  The service to set.
	 */
	private void setService(Service service) {
		if(service==null){
			throw new IllegalArgumentException("Service can't be null");
		}
		this.service = service;
	}

	@Override
	public String toString() {
		return super.toString() + ", service=" + service ;
	}

}
